#!/usr/bin/env python3
import sys

lookup = {
    '(': 1, '[': 1, '{': 1, '<': 1,
    ')': -1, ']': -1, '}': -1, '>': -1,
}

expected = {
    ')': '(', ']': '[', '}': '{', '>': '<',
    '(': ')', '[': ']', '{': '}', '<': '>'
}

score = {
    ')': 3,
    ']': 57,
    '}': 1197,
    '>': 25137
}

balance = 0
for line in sys.stdin:
    line = line.rstrip('\n')
    print(line)

    # find balance and score of line
    brackets = 0
    stack = []
    for c in line:
        closing = lookup[c] < 0
        brackets += lookup[c]
        # print with indentation
        print('  ' * (brackets + (1 if closing else 0)), c, brackets, lookup[c])
        # manipulate stack to check for correctness and score
        if not closing:
            # to reduce memory consumption, one could count repeating braces
            stack.append(c)
        else:
            bracket = stack.pop()
            if bracket != expected[c]:
                print(f'closure incorrect: {expected[bracket]} == {c} = {expected[bracket] == c}')
                balance += score[c]
    print(f'final bracket balance {brackets}')

    # find closure to line
    print('a closure look like')
    for _ in range(len(stack)):
        b = expected[stack.pop()]
        closing = lookup[b] < 0
        brackets += lookup[b]
        print('  ' * (brackets + (1 if closing else 0)), b, brackets, lookup[b])

print(f'file gets a score of {balance}')
